﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _04_Array类
{
    public class Person : IComparable<Person>//IComparable是在类的内部实现的排序
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Person()
        { }
        public Person(int id,string name)
        {
            this.Id = id;
            this.Name = name;
 
        }

        public int CompareTo(Person other)
        {
            if (other == null) throw new ArgumentNullException("other");
            int result= this.Id.CompareTo(other.Id);
            if (result==0)//如果Id相同，则result返回为0
            {
                result= this.Name.CompareTo(other.Name);
            }
            return result;
        }
    }
}
